package com.yohann.designPattern.memento;

/**
 * <p>
 * 客户端
 * </p>
 *
 * @author Yohann
 * @since 2021/2/13 15:58
 */
public class Client {
    public static void main(String[] args) {
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();

        originator.setState("状态#1 余额999");
        caretaker.add(originator.saveState());

        originator.setState("状态#2 余额666");
        caretaker.add(originator.saveState());

        originator.setState("状态#3 余额333");
        caretaker.add(originator.saveState());

        /**
         * 当前状态：
         * 状态#3 余额333
         */
        System.out.println(originator.getState());
        /**
         * 恢复到状态1：
         * 状态#1 余额999
         */
        originator.setState(caretaker.get(0).getState());
        System.out.println(originator.getState());
    }
}